<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>cgghrd.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="CGGHRD.1"></a><a href="cgghrd.f.html#CGGHRD.1">CGGHRD</a>( COMPQ, COMPZ, N, ILO, IHI, A, LDA, B, LDB, Q,
     $                   LDQ, Z, LDZ, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      CHARACTER          COMPQ, COMPZ
      INTEGER            IHI, ILO, INFO, LDA, LDB, LDQ, LDZ, N
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      COMPLEX            A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
     $                   Z( LDZ, * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="CGGHRD.20"></a><a href="cgghrd.f.html#CGGHRD.1">CGGHRD</a> reduces a pair of complex matrices (A,B) to generalized upper
</span><span class="comment">*</span><span class="comment">  Hessenberg form using unitary transformations, where A is a
</span><span class="comment">*</span><span class="comment">  general matrix and B is upper triangular.  The form of the generalized
</span><span class="comment">*</span><span class="comment">  eigenvalue problem is
</span><span class="comment">*</span><span class="comment">     A*x = lambda*B*x,
</span><span class="comment">*</span><span class="comment">  and B is typically made upper triangular by computing its QR
</span><span class="comment">*</span><span class="comment">  factorization and moving the unitary matrix Q to the left side
</span><span class="comment">*</span><span class="comment">  of the equation.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  This subroutine simultaneously reduces A to a Hessenberg matrix H:
</span><span class="comment">*</span><span class="comment">     Q**H*A*Z = H
</span><span class="comment">*</span><span class="comment">  and transforms B to another upper triangular matrix T:
</span><span class="comment">*</span><span class="comment">     Q**H*B*Z = T
</span><span class="comment">*</span><span class="comment">  in order to reduce the problem to its standard form
</span><span class="comment">*</span><span class="comment">     H*y = lambda*T*y
</span><span class="comment">*</span><span class="comment">  where y = Z**H*x.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  The unitary matrices Q and Z are determined as products of Givens
</span><span class="comment">*</span><span class="comment">  rotations.  They may either be formed explicitly, or they may be
</span><span class="comment">*</span><span class="comment">  postmultiplied into input matrices Q1 and Z1, so that
</span><span class="comment">*</span><span class="comment">       Q1 * A * Z1**H = (Q1*Q) * H * (Z1*Z)**H
</span><span class="comment">*</span><span class="comment">       Q1 * B * Z1**H = (Q1*Q) * T * (Z1*Z)**H
</span><span class="comment">*</span><span class="comment">  If Q1 is the unitary matrix from the QR factorization of B in the
</span><span class="comment">*</span><span class="comment">  original equation A*x = lambda*B*x, then <a name="CGGHRD.43"></a><a href="cgghrd.f.html#CGGHRD.1">CGGHRD</a> reduces the original
</span><span class="comment">*</span><span class="comment">  problem to generalized Hessenberg form.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  COMPQ   (input) CHARACTER*1
</span><span class="comment">*</span><span class="comment">          = 'N': do not compute Q;
</span><span class="comment">*</span><span class="comment">          = 'I': Q is initialized to the unit matrix, and the
</span><span class="comment">*</span><span class="comment">                 unitary matrix Q is returned;
</span><span class="comment">*</span><span class="comment">          = 'V': Q must contain a unitary matrix Q1 on entry,
</span><span class="comment">*</span><span class="comment">                 and the product Q1*Q is returned.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  COMPZ   (input) CHARACTER*1
</span><span class="comment">*</span><span class="comment">          = 'N': do not compute Q;
</span><span class="comment">*</span><span class="comment">          = 'I': Q is initialized to the unit matrix, and the
</span><span class="comment">*</span><span class="comment">                 unitary matrix Q is returned;
</span><span class="comment">*</span><span class="comment">          = 'V': Q must contain a unitary matrix Q1 on entry,
</span><span class="comment">*</span><span class="comment">                 and the product Q1*Q is returned.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The order of the matrices A and B.  N &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  ILO     (input) INTEGER
</span><span class="comment">*</span><span class="comment">  IHI     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          ILO and IHI mark the rows and columns of A which are to be
</span><span class="comment">*</span><span class="comment">          reduced.  It is assumed that A is already upper triangular
</span><span class="comment">*</span><span class="comment">          in rows and columns 1:ILO-1 and IHI+1:N.  ILO and IHI are
</span><span class="comment">*</span><span class="comment">          normally set by a previous call to <a name="CGGBAL.71"></a><a href="cggbal.f.html#CGGBAL.1">CGGBAL</a>; otherwise they
</span><span class="comment">*</span><span class="comment">          should be set to 1 and N respectively.
</span><span class="comment">*</span><span class="comment">          1 &lt;= ILO &lt;= IHI &lt;= N, if N &gt; 0; ILO=1 and IHI=0, if N=0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  A       (input/output) COMPLEX array, dimension (LDA, N)
</span><span class="comment">*</span><span class="comment">          On entry, the N-by-N general matrix to be reduced.
</span><span class="comment">*</span><span class="comment">          On exit, the upper triangle and the first subdiagonal of A
</span><span class="comment">*</span><span class="comment">          are overwritten with the upper Hessenberg matrix H, and the
</span><span class="comment">*</span><span class="comment">          rest is set to zero.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDA     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array A.  LDA &gt;= max(1,N).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  B       (input/output) COMPLEX array, dimension (LDB, N)
</span><span class="comment">*</span><span class="comment">          On entry, the N-by-N upper triangular matrix B.
</span><span class="comment">*</span><span class="comment">          On exit, the upper triangular matrix T = Q**H B Z.  The
</span><span class="comment">*</span><span class="comment">          elements below the diagonal are set to zero.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDB     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array B.  LDB &gt;= max(1,N).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Q       (input/output) COMPLEX array, dimension (LDQ, N)
</span><span class="comment">*</span><span class="comment">          On entry, if COMPQ = 'V', the unitary matrix Q1, typically
</span><span class="comment">*</span><span class="comment">          from the QR factorization of B.
</span><span class="comment">*</span><span class="comment">          On exit, if COMPQ='I', the unitary matrix Q, and if
</span><span class="comment">*</span><span class="comment">          COMPQ = 'V', the product Q1*Q.
</span><span class="comment">*</span><span class="comment">          Not referenced if COMPQ='N'.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDQ     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array Q.
</span><span class="comment">*</span><span class="comment">          LDQ &gt;= N if COMPQ='V' or 'I'; LDQ &gt;= 1 otherwise.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Z       (input/output) COMPLEX array, dimension (LDZ, N)
</span><span class="comment">*</span><span class="comment">          On entry, if COMPZ = 'V', the unitary matrix Z1.
</span><span class="comment">*</span><span class="comment">          On exit, if COMPZ='I', the unitary matrix Z, and if
</span><span class="comment">*</span><span class="comment">          COMPZ = 'V', the product Z1*Z.
</span><span class="comment">*</span><span class="comment">          Not referenced if COMPZ='N'.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDZ     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array Z.
</span><span class="comment">*</span><span class="comment">          LDZ &gt;= N if COMPZ='V' or 'I'; LDZ &gt;= 1 otherwise.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO    (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0:  successful exit.
</span><span class="comment">*</span><span class="comment">          &lt; 0:  if INFO = -i, the i-th argument had an illegal value.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Further Details
</span><span class="comment">*</span><span class="comment">  ===============
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  This routine reduces A to Hessenberg and B to triangular form by
</span><span class="comment">*</span><span class="comment">  an unblocked reduction, as described in _Matrix_Computations_,
</span><span class="comment">*</span><span class="comment">  by Golub and van Loan (Johns Hopkins Press).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      COMPLEX            CONE, CZERO
      PARAMETER          ( CONE = ( 1.0E+0, 0.0E+0 ),
     $                   CZERO = ( 0.0E+0, 0.0E+0 ) )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      LOGICAL            ILQ, ILZ
      INTEGER            ICOMPQ, ICOMPZ, JCOL, JROW
      REAL               C
      COMPLEX            CTEMP, S
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      LOGICAL            <a name="LSAME.138"></a><a href="lsame.f.html#LSAME.1">LSAME</a>
      EXTERNAL           <a name="LSAME.139"></a><a href="lsame.f.html#LSAME.1">LSAME</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           <a name="CLARTG.142"></a><a href="clartg.f.html#CLARTG.1">CLARTG</a>, <a name="CLASET.142"></a><a href="claset.f.html#CLASET.1">CLASET</a>, <a name="CROT.142"></a><a href="crot.f.html#CROT.1">CROT</a>, <a name="XERBLA.142"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          CONJG, MAX
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Decode COMPQ
</span><span class="comment">*</span><span class="comment">
</span>      IF( <a name="LSAME.151"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( COMPQ, <span class="string">'N'</span> ) ) THEN
         ILQ = .FALSE.
         ICOMPQ = 1
      ELSE IF( <a name="LSAME.154"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( COMPQ, <span class="string">'V'</span> ) ) THEN
         ILQ = .TRUE.
         ICOMPQ = 2
      ELSE IF( <a name="LSAME.157"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( COMPQ, <span class="string">'I'</span> ) ) THEN
         ILQ = .TRUE.
         ICOMPQ = 3
      ELSE
         ICOMPQ = 0
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Decode COMPZ
</span><span class="comment">*</span><span class="comment">
</span>      IF( <a name="LSAME.166"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( COMPZ, <span class="string">'N'</span> ) ) THEN
         ILZ = .FALSE.
         ICOMPZ = 1
      ELSE IF( <a name="LSAME.169"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( COMPZ, <span class="string">'V'</span> ) ) THEN
         ILZ = .TRUE.
         ICOMPZ = 2
      ELSE IF( <a name="LSAME.172"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( COMPZ, <span class="string">'I'</span> ) ) THEN
         ILZ = .TRUE.
         ICOMPZ = 3
      ELSE
         ICOMPZ = 0
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Test the input parameters.
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
      IF( ICOMPQ.LE.0 ) THEN
         INFO = -1
      ELSE IF( ICOMPZ.LE.0 ) THEN
         INFO = -2
      ELSE IF( N.LT.0 ) THEN
         INFO = -3
      ELSE IF( ILO.LT.1 ) THEN
         INFO = -4
      ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
         INFO = -5
      ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
         INFO = -7
      ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
         INFO = -9
      ELSE IF( ( ILQ .AND. LDQ.LT.N ) .OR. LDQ.LT.1 ) THEN
         INFO = -11
      ELSE IF( ( ILZ .AND. LDZ.LT.N ) .OR. LDZ.LT.1 ) THEN
         INFO = -13
      END IF
      IF( INFO.NE.0 ) THEN
         CALL <a name="XERBLA.202"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="CGGHRD.202"></a><a href="cgghrd.f.html#CGGHRD.1">CGGHRD</a>'</span>, -INFO )
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Initialize Q and Z if desired.
</span><span class="comment">*</span><span class="comment">
</span>      IF( ICOMPQ.EQ.3 )
     $   CALL <a name="CLASET.209"></a><a href="claset.f.html#CLASET.1">CLASET</a>( <span class="string">'Full'</span>, N, N, CZERO, CONE, Q, LDQ )
      IF( ICOMPZ.EQ.3 )
     $   CALL <a name="CLASET.211"></a><a href="claset.f.html#CLASET.1">CLASET</a>( <span class="string">'Full'</span>, N, N, CZERO, CONE, Z, LDZ )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Quick return if possible
</span><span class="comment">*</span><span class="comment">
</span>      IF( N.LE.1 )
     $   RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Zero out lower triangle of B
</span><span class="comment">*</span><span class="comment">
</span>      DO 20 JCOL = 1, N - 1
         DO 10 JROW = JCOL + 1, N
            B( JROW, JCOL ) = CZERO
   10    CONTINUE
   20 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Reduce A and B
</span><span class="comment">*</span><span class="comment">
</span>      DO 40 JCOL = ILO, IHI - 2
<span class="comment">*</span><span class="comment">
</span>         DO 30 JROW = IHI, JCOL + 2, -1
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Step 1: rotate rows JROW-1, JROW to kill A(JROW,JCOL)
</span><span class="comment">*</span><span class="comment">
</span>            CTEMP = A( JROW-1, JCOL )
            CALL <a name="CLARTG.235"></a><a href="clartg.f.html#CLARTG.1">CLARTG</a>( CTEMP, A( JROW, JCOL ), C, S,
     $                   A( JROW-1, JCOL ) )
            A( JROW, JCOL ) = CZERO
            CALL <a name="CROT.238"></a><a href="crot.f.html#CROT.1">CROT</a>( N-JCOL, A( JROW-1, JCOL+1 ), LDA,
     $                 A( JROW, JCOL+1 ), LDA, C, S )
            CALL <a name="CROT.240"></a><a href="crot.f.html#CROT.1">CROT</a>( N+2-JROW, B( JROW-1, JROW-1 ), LDB,
     $                 B( JROW, JROW-1 ), LDB, C, S )
            IF( ILQ )
     $         CALL <a name="CROT.243"></a><a href="crot.f.html#CROT.1">CROT</a>( N, Q( 1, JROW-1 ), 1, Q( 1, JROW ), 1, C,
     $                    CONJG( S ) )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Step 2: rotate columns JROW, JROW-1 to kill B(JROW,JROW-1)
</span><span class="comment">*</span><span class="comment">
</span>            CTEMP = B( JROW, JROW )
            CALL <a name="CLARTG.249"></a><a href="clartg.f.html#CLARTG.1">CLARTG</a>( CTEMP, B( JROW, JROW-1 ), C, S,
     $                   B( JROW, JROW ) )
            B( JROW, JROW-1 ) = CZERO
            CALL <a name="CROT.252"></a><a href="crot.f.html#CROT.1">CROT</a>( IHI, A( 1, JROW ), 1, A( 1, JROW-1 ), 1, C, S )
            CALL <a name="CROT.253"></a><a href="crot.f.html#CROT.1">CROT</a>( JROW-1, B( 1, JROW ), 1, B( 1, JROW-1 ), 1, C,
     $                 S )
            IF( ILZ )
     $         CALL <a name="CROT.256"></a><a href="crot.f.html#CROT.1">CROT</a>( N, Z( 1, JROW ), 1, Z( 1, JROW-1 ), 1, C, S )
   30    CONTINUE
   40 CONTINUE
<span class="comment">*</span><span class="comment">
</span>      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="CGGHRD.262"></a><a href="cgghrd.f.html#CGGHRD.1">CGGHRD</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
